home *** CD-ROM | disk | FTP | other *** search
/ Shareware Grab Bag / Shareware Grab Bag.iso / 090 / wheels2.arc / QUEUE.PAS < prev    next >
Pascal/Delphi Source File  |  1985-06-28  |  2KB  |  60 lines

  1. {@@@@@@@@@@@ copyright (C) 1984 by Neil J. Rubenking @@@@@@@@@@@@@@@@@@@@@@@@
  2. The purchaser of these procedures and functions may include them in COMPILED
  3. programs freely, but may not sell or give away the source text.
  4.  
  5.    This program is a simple demo of the use of POINTERS to produce
  6.    a QUEUE.  Please note that the amount of memory set aside for
  7.    the QUEUE is ZERO.  As each item is added, a chunk of memory is
  8.    devoted to it.  This is very often much more efficient than
  9.    an ARRAY, which must be declared to be a specific size.
  10.  
  11.  
  12. }
  13.  
  14.  
  15. {@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@}
  16. type
  17.   ItemType = array[1..1016] of byte;
  18. {$I queue.lib}
  19. {$I kavail.lib}
  20. {$I getkeys.lib}
  21.  
  22. var
  23.   Klist, Kpointer : ListType;
  24.   DummyItem       : ItemType;
  25.   N, Initial_K    : integer;
  26.   C, D            : char;
  27. {@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@}
  28. begin
  29.   window(10,1,70,25);
  30.   ClrScr;
  31.   WriteLn('This program shows the effect of adding items to a queue.');
  32.   WriteLn('After each addition, it shows the memory available in K');
  33.   WriteLn('Since each item is one K in size (1016 bytes of data and');
  34.   WriteLn('8 bytes for the pointer), additions are clearly visible.');
  35.   WriteLn('    Each time you press a key, an item will be added.  To');
  36.   WriteLn('stop adding and dispose of all the items, press <Esc>');
  37.   WriteLn;
  38.   Initial_K := K_Available;
  39.   WriteLn('You start with ',K_available,'K available.');
  40.   window(10,10,70,25);
  41.   for N := 1 to 1016 do
  42.     DummyItem[N] := N and $00FF;    { I have heard that for reducing an }
  43.                                     { integer to a byte, "and $00FF" is }
  44.                                     { much faster than "mod 256".       }
  45.   N := 0;
  46.   repeat
  47.     GetKeys(C,D);
  48.     N := N + 1;
  49.     AddItem(DummyItem,KList,KPointer);
  50.     WriteLn('Added ',N,' items.  ',K_available,'K available.');
  51.   until (C = #27) and (D = #0);
  52.   WriteLn;
  53.   WriteLn('You started with ',Initial_K,'K bytes.');
  54.   WriteLn('After adding ',N,' items, you have ',K_available,'K bytes.');
  55.   WriteLn;
  56.   DisposeAll(KList);
  57.   WriteLn('I just DISPOSEd of the list.  You have ',K_available,'K bytes.');
  58. end.
  59.  
  60.